<?php 
//$o_PoRecepcionBN = $a_Maestros['o_PoRecepcionBN'];

$contextMenu[0]["link"]      = "javascript:fn_nuevo()";
$contextMenu[0]["linkIcon"]  = "application_add.png";
$contextMenu[0]["linkTitle"] = "Nueva Transferencia";

$contextMenu[1]["link"]      = "javascript:listarTransferencias()";
$contextMenu[1]["linkIcon"]  = "application_view_list.png";
$contextMenu[1]["linkTitle"] = "Lista";
if ($o_ImTransferBN->getTransferId() && $o_ImTransferBN->getEstado()!= "C"){
    $contextMenu[2]["link"]      = "?ImTransfer&accion=eliminarIngreso&s_TransferId=".$o_ImTransferBN->getTransferId();
    $contextMenu[2]["linkIcon"]  = "page_white_delete.png";
    $contextMenu[2]["linkTitle"] = "Eliminar Transferencias";
} 
?>


<style>
.error {color: red;font-style: italic;}  
</style>
<script>
var iCorrelativoRecep = 0;
</script>
<body>
<div id="main">
    <?php include $_SERVER['DOCUMENT_ROOT'].'/gourmet-express/trunk/src/views/header.inc'; ?>
    <div id="zonaContenedor">
        <h3>:: Transferencia de Mercaderia</h3>
        <div id="module">
                <div>
                    <form id="form_editar" action="javascript:fn_actualizar();">
                    <table width="100%">
                        <tr>
                            <td id="keyLabel" width="20%">Transferencia Nro</td>
                            <td width="30"><?php echo $o_ImTransferBN->getTransferId();?><input type="hidden" name='s_TransferId' id='s_TransferId' value='<?php echo $o_ImTransferBN->getTransferId();?>'</td>
                            <td id="label" width="20%">Status</td>
                            <td>    
                                <input name="statusDsc" id='statusDsc' type="text" size="15" value="<? if ($o_ImTransferBN->getEstado()== "C"){echo "Cerrado";} ?>" disabled>  
                                <!--
                                <select name="s_Estado" id="s_Estado" class="required">
                                    <option value="">-- seleccione --</option><?php
                                    foreach ($a_TransEsta as $key => $obj){?>
                                    <option value="<?php echo $obj->getValorId();?>"  <?php if($obj->getValorId()==$o_ImTransferBN->getEstado()){ echo "selected";}?>><?php echo $obj->getDescripcion();?></option><?php
                                    }?>
                                </select>
                                -->
                            </td>
                        </tr>
                        <tr>
                            <td id="label">Tipo</td>
                            <td>
                                <select name="s_TipoTransfer" id="s_TipoTransfer" class="required">
                                    <option value="">-- seleccione --</option><?php
                                    foreach ($a_TipoTransf as $key => $obj){?>
                                    <option value="<?php echo $obj->getValorId();?>"  <?php if($obj->getValorId()==$o_ImTransferBN->getTipoTransfer()){ echo "selected";}?> ><?php echo $obj->getDescripcion();?></option><?php
                                    }?>
                                </select>
                            </td>
                            <td id="label">Doc Transferencia</td>
                            <td><input type="text" name="s_DocTransfer" id="s_DocTransfer" class="required" size="12" value='<?php echo $o_ImTransferBN->getDocTransfer();?>' /></td>
                        </tr>
                        <tr>
                            <td id="label">Almacen Origen</td>
                            <td>
                                <select name="s_AlmOrigenId" id="s_AlmOrigenId" class="required">
                                <option value="">-- seleccione --</option><?php
                                foreach ($ao_ImAlmacenBN as $key => $obj){?>
                                <option value="<?php echo $obj->getAlmacenId();?>"  <?php if($obj->getAlmacenId()==$o_ImTransferBN->getAlmOrigenId()){ echo "selected";}?> ><?php echo $obj->getNombre();?></option><?php
                                }?>
                                </select>
                            </td>
                            <td id="label">Doc Referencia</td>
                            <td><input type="text" name="s_DocRef" id="fechaGuiaRem" size="12" value='<?php echo $o_ImTransferBN->getDocRef();?>' class="required" /></td>
                        </tr>                 
                        <tr>
                            <td id="label">Almacen Destino</td>
                            <td nowrap>
                            	<select name="s_AlmDestinoId" id="s_AlmDestinoId" class="required">
                                    <option value="">-- seleccione --</option><?php
                                    foreach ($ao_ImAlmacenBN as $key => $obj){?>
                                    <option value="<?php echo $obj->getAlmacenId();?>"  <?php if($obj->getAlmacenId()==$o_ImTransferBN->getAlmDestinoId()){ echo "selected";}?> ><?php echo $obj->getNombre();?></option><?php
                                    }?>
                                </select>
                            </td>
                            <td id="label">&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td id="label">Observaciones</td>
                            <td>
                            <textarea name="obs" cols="40" rows="2"><?php echo $o_ImTransferBN->getObs();?></textarea></td>
                            <td id="label" valign="top">&nbsp;</td>
                            <td valign="top">&nbsp;</td>
                        </tr>        
                        <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        </tr>
                    </table>
                    <table width=100%>
                        <tr>
                            <td></td>
                            <td align=right>
                                <? if ($o_ImTransferBN->getEstado()!= "C"){ ?>
                                        <input type="button" id="btn_addDetalle" name="btn_agregarDetalle" onclick="javascript: add_TR_TbodyRecep()" value="Agregar detalle">
                                <? } ?>
                            </td>
                        </tr>
                    </table>

                    <table width="100%" >
                        <tr>
                            <td colspan="4">
                                <table width="100%" cellspacing="1" id='tableNuevoRecep'>
                                    <thead>
                                        <tr bgcolor="#CCCCCC" >
                                            <td>Codigo</td>
                                            <td width="35%">Descripcion</td>
                                            <td>UM</td>
                                            <td>Cantidad</td>                                        
                                            <td></td>                                 
                                        </tr>
                                    </thead>
                                    <tbody><?php
                                        if($o_ImTransferBN->getObj_ImTransferDet())
                                        {
                                            $correlaTivo = 1;
                                            foreach ( $o_ImTransferBN->getObj_ImTransferDet() as $iKey => $objRcp )
                                            {
                                                $id_ItemCode = "itemCode_".$correlaTivo;
                        						
                        						?>
                                              <tr bgcolor='#FFFFFF'>
                                              <td ><input type='text' itemG='itemG' id='<?php echo $id_ItemCode;?>' name='a_ItemId[<?php echo $correlaTivo;?>]' value="<?php echo $objRcp->getArticuloId() ;?>" size='15' style='width: 100px;' class='loadF2 required' ></td>
                                              <td id='txtDesc' desc='desc'><?php echo $objRcp->get_oDetalleItemBean()->getDescripcion();?></td>
                                              <td UoM='UoM' ><?php echo $objRcp->get_oDetalleItemBean()->getUndMedida();?></td>
                                              <td ><input type='text' cant='cant' name='a_Cant[<?php echo $correlaTivo;?>]' size='5' value="<?php echo $objRcp->getCant();?>" class='number required' style='text-align:right' ></td>                                              
                                              <td align='right'>
                                                  <? if ($o_ImTransferBN->getEstado()!= "C"){ ?>
                                                        <img border='0' style='cursor:pointer' title='Eliminar Registro' src='/gourmet-express/trunk/imgs/icons/delete_icon.png' onclick='delete_TR_TbodyRecep(this)'>
                                                  <? } ?>      
                                              </td>
                                              </tr>
                                              <script> loadAutocompleteItem('<?php echo $id_ItemCode; ?>'); iCorrelativoRecep=<?php echo $correlaTivo;?>;</script><?php
                                              
                                              $correlaTivo++;
                                            
                                            }
                                        }?>
                                            
                                    </tbody>                                   															
                                </table>
                            </td>
                        </tr>
                    </table>
                    <? if ($o_ImTransferBN->getEstado()!= "C"){ ?>
                            <table width="100%">
                                <tr>
                                    <td>
                                        <?php if ($correlaTivo){ ?>
                                                    <input class="mainBtn" type="button" id="btn_cerrar"name="btn_cerrar" onclick="javascript: fn_cerrar()" value="Transferir">
                                        <?php } ?>   
                                    </td>
                                    <td width="90%" align="right"><input class="mainBtn" type="button" name="guardar" value="Guardar" onclick="javascript: fn_actualizar();"></td>
                                    <td align="right"><input class="mainBtn" type="button" id="btn_cancelar"name="btn_cancelar" onclick="javascript: listarTransferencias()" value="Cancelar"></td>  						 
                                <tr>	
                            </table> 
                    <?}?>
                    <br>&nbsp;
                    <div id="moduleSectionDetalleAdd"> </div>    
                </div>
            </form>
        <div id="gridFase" style="top:237px"></div>
    </div>
    <div id="footer"></div>
    <div id="moduleSectionDetalleAddList"> </div>
</div>
<script>



add_TR_TbodyRecep = function ()
{
  
  iCorrelativoRecep = iCorrelativoRecep+1
  
  var id_ItemCode = "itemCode_"+iCorrelativoRecep;
  
  var sTr='';
	sTr+="<tr bgcolor='#FFFFFF'>";
	sTr+="<td ><input type='text' itemG='itemG' id='"+id_ItemCode+"' name='a_ItemId["+iCorrelativoRecep+"]' size='15' style='width: 100px;' class='loadF2 required' ></td>";
	sTr+="<td id='txtDesc' desc='desc'>&nbsp;</td>";
	sTr+="<td UoM='UoM'>&nbsp;</td>";
	sTr+="<td ><input type='text' cant='cant' name='a_Cant["+iCorrelativoRecep+"]' size='5' class='number required' style='text-align:right' ></td>";
    sTr+="<td align='right'><img border='0' style='cursor:pointer' title='Eliminar Registro' src='/gourmet-express/trunk/imgs/icons/delete_icon.png' onclick='delete_TR_TbodyRecep(this)'></td>"; 		
    sTr+="</tr>";
    
  $("#tableNuevoRecep tbody").append(sTr);
    
  loadAutocompleteItem(id_ItemCode);
}

delete_TR_TbodyRecep = function (obj)
{
 $(obj).parents('tr').first().remove();
 evalMontos(); 
}  

$("#form_editar").validate();
	

</script>
